// const {API, COMM} = getApp().globalData
const {API, COMM} = getApp()

Page({
  /**
   * 页面的初始数据
   */
  data: {
    searchUrl: COMM.apiList.DetailInfo,
    goodsData: null,
    // {
        // images: ['/images/zjnxjj.png', '/images/zjnxjj.png', COMM.baseUrl +'/goods-image/微信图片_20240325132446.jpg'],
        // detailList: [
        //     {key:"品类", value:"30483 内衣洗"},
        //     {key:"商品类型", value:"一般商品"},
        //     {key:"类别码", value:"否"},
        //     {key:"商品编码", value:"304830006"},
        //     {key:"商品名称", value:"超能内衣洗衣液860g"},
        //     {key:"品牌编码", value:"10127"},
        //     {key:"商品品牌", value:"超能"},
        //     {key:"商品条码", value:"6910019022563"},
        // ],
        // promptionList: [
        //     {key:"商品货号", value:""},
        //     {key:"规格型号", value:"1*12"},
        //     {key:"计量属性", value:"标准"},
        //     {key:"保质期", value:"1095天"},
        //     {key:"计量单位", value:"瓶"},
        //     {key:"小数控制", value:"是"},
        //     {key:"收货提前", value:"0天"},
        // ]
    // },
    txm: "6910019023324"
  },

  onGoodsDataLoad(data) {
    const {detail, promption, images} = data

    let detailList = []
    for (let key in detail) {
      detailList.push({key, value: detail[key]})
    }

    let promptionList = []
    for (let key in promption) {
      promptionList.push({key, value: promption[key]})
    }

    this.setData({
      goodsData: {
        images, detailList, promptionList
      }
    })
  },

  onGetGoodsInfo(txm) {
    let that = this
    API.get(COMM.apiList.DetailInfo+'/'+txm).then(
        data => {
          that.onGoodsDataLoad(data)
        }
    )
  },

  onSearch(event) {
    this.onGoodsDataLoad(event.detail)
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // console.log('--------' , )
    // let txm = "6910019023324"
    let txm = options.txm
    if (txm != null) {
        this.setData({txm})
        this.onGetGoodsInfo(txm)
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.onGetGoodsInfo(txm)
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})